<?php

/**
 * user filter form base class.
 *
 * @package    worldmap
 * @subpackage filter
 * @author     Your name here
 * @version    SVN: $Id: sfDoctrineFormFilterGeneratedInheritanceTemplate.php 24171 2009-11-19 16:37:50Z Kris.Wallsmith $
 */
abstract class BaseuserFormFilter extends entityFormFilter
{
  protected function setupInheritance()
  {
    parent::setupInheritance();

    $this->widgetSchema   ['entity_id'] = new sfWidgetFormFilterInput(array('with_empty' => false));
    $this->validatorSchema['entity_id'] = new sfValidatorSchemaFilter('text', new sfValidatorInteger(array('required' => false)));

    $this->widgetSchema   ['email'] = new sfWidgetFormFilterInput();
    $this->validatorSchema['email'] = new sfValidatorPass(array('required' => false));

    $this->widgetSchema   ['has_firmwarekit'] = new sfWidgetFormChoice(array('choices' => array('' => 'yes or no', 1 => 'yes', 0 => 'no')));
    $this->validatorSchema['has_firmwarekit'] = new sfValidatorChoice(array('required' => false, 'choices' => array('', 1, 0)));

    $this->widgetSchema   ['controller_list'] = new sfWidgetFormDoctrineChoice(array('multiple' => true, 'model' => 'controller'));
    $this->validatorSchema['controller_list'] = new sfValidatorDoctrineChoice(array('multiple' => true, 'model' => 'controller', 'required' => false));

    $this->widgetSchema->setNameFormat('user_filters[%s]');
  }

  public function addControllerListColumnQuery(Doctrine_Query $query, $field, $values)
  {
    if (!is_array($values))
    {
      $values = array($values);
    }

    if (!count($values))
    {
      return;
    }

    $query->leftJoin('r.userController userController')
          ->andWhereIn('userController.controller_id', $values);
  }

  public function getModelName()
  {
    return 'user';
  }

  public function getFields()
  {
    return array_merge(parent::getFields(), array(
      'entity_id' => 'Number',
      'email' => 'Text',
      'has_firmwarekit' => 'Boolean',
      'controller_list' => 'ManyKey',
    ));
  }
}
